package com.chenyuxin.ilp;

import com.chenyuxin.ilp.service.user.VerificationCodeService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.web.client.RestTemplate;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;

@SpringBootTest
public class SmsTest {
    @Autowired
    private VerificationCodeService verificationCodeService;
    @Test
    void sendSmsTest(){
        String url = "https://api.smsbao.com/sms";
        String username = "chenyuxin0328";
        String password = "eb39749f92c54c29920f74bdd7588041";
        String mobile = "13950145609"; // 替换为目标手机号
        String content = "【智能学习平台】您的验证码是123456"; // 短信内容

//        // 短信内容需要进行 URL 编码
//        String encodedContent = URLEncoder.encode(content, StandardCharsets.UTF_8);

        // 构造完整的 URL
        String fullUrl = String.format("%s?u=%s&p=%s&m=%s&c=%s", url, username, password, mobile, content);

        // 发送 GET 请求
        RestTemplate restTemplate = new RestTemplate();
        String response = restTemplate.getForObject(fullUrl, String.class);

        // 输出返回结果
        System.out.println("SMS API Response: " + response);
    }
    @Test
    void testSmsService(){
        verificationCodeService.sendLoginVerificationCode("13950145609","captcha:7e67a1ee3f5b4e7b878a716fffe9b875","46xf");
    }
}
